#ifndef BATTLE_REGION_H_
#define BATTLE_REGION_H_

// INCLUDES //
#include "region.h"
#include "object.h"
#include "graphics/surface.h"
#include "effects_manager.h"
#include "object/player.h"
#include "object/animation.h"
#include <string>
//////////////

// CONSTANTS //
#define BAR_LEFT_INDENT			5
#define BAR_RIGHT_INDENT		10
#define BAR_WIDTH				10
#define BAR_SPACING				5
///////////////

/**
* A region that shows the player's name, health, and card count.
* 
* @author dfoelber
**/
class BattleRegion : public Region, public EffectsListener
{
public:
	/**
	* Constructor
	**/
	BattleRegion();
	
	/**
	* Destructor
	**/
	virtual ~BattleRegion();
	
	/**
	* Sets the region's boundary.
	* 
	* Overridden from Region.
	* 
	* @param x The boundary's X coordinate
	* @param y The boundary's Y coordinate
	* @param width The boundary's width
	* @param height The boundary's height
	**/
	virtual void SetBoundary( int x, int y, int width, int height );
	
	/**
	* Notify the region of an event.
	* 
	* Overridden from Region.
	* 
	* @param event The event that happened
	* @return If the region used the event
	**/
	virtual bool ProcessEvent( SDL_Event event );
	
	/**
	* Notifies of time passing.
	* 
	* Overridden from Region.
	* 
	* @param The amount of time, in milliseconds, that passed since the last call
	**/
	virtual void TimePassed( int ms );
	
	/**
	* Renders the objects on the background
	* 
	* Overridden from Region.
	**/
	virtual void Render();
	
	/**
	* An effect's state has changed.
	* 
	* Overridden from EffectsListener
	* 
	* @param effect The effect that is updated
	**/
	virtual void EffectStateChanged( Effect* effect );
	
	/*
	* Sets the player's health.
	* 
	* @param health The player's health
	**/
	void SetHealth( int health ) { playerHealth = health; }
	
	/*
	* Gets the player's health.
	* 
	* @return The player's health
	**/
	int GetHealth() { return playerHealth; }
	
	/*
	* Sets the player's total health.
	* 
	* @param health The player's total health
	**/
	void SetTotalHealth( int health ) { totalPlayerHealth = health; }
	
	/*
	* Gets the player's total health.
	* 
	* @return The player's total health
	**/
	int GetTotalHealth() { return totalPlayerHealth; }
	
	/*
	* Sets the enemy's health.
	* 
	* @param health The enemy's health
	**/
	void SetEnemyHealth( int health ) { enemyHealth = health; }
	
	/*
	* Gets the enemy's health.
	* 
	* @return The enemy's health
	**/
	int GetEnemyHealth() { return enemyHealth; }
	
	/*
	* Sets the enemy's total health.
	* 
	* @param health The enemy's total health
	**/
	void SetTotalEnemyHealth( int health ) { totalEnemyHealth = health; }
	
	/*
	* Gets the enemy's total health.
	* 
	* @return The enemy's total health
	**/
	int GetTotalEnemyHealth() { return totalEnemyHealth; }
	
	/**
	* Checks if the player is dead.
	*
	* @return If the player is dead
	**/
	bool IsPlayerDead() { return playerHealthPercent == 0 && playerHealth == 0; }
	
	/**
	* Checks if the enemy is dead.
	*
	* @return If the enemy is dead
	**/
	bool IsEnemyDead() { return enemyHealthPercent == 0 && enemyHealth == 0; }
	
private:
	/*
	* Calculates the player's health as a percentage.
	* 
	* @return The player's health.
	**/
	int GetPercentHealth();
	
	/*
	* Calculates the enemy's health as a percentage.
	* 
	* @return The enemy's health.
	**/
	int GetPercentEnemyHealth();
	
	/**
	* Gets the origin coordinates.
	* 
	* @param effect The effect to extract the origin.
	* @param x The origin's X coordinate.
	* @param y The origin's y coordinate.
	**/
	void GetOriginCoords(Effect* effect, int* x, int* y);

	/**
	* Gets the target coordinates.
	* 
	* @param effect The effect to extract the target.
	* @param A list of target points
	**/
	vector<Point> GetTargetCoords(Effect* effect);
	
	/**
	* Starts a fireball animation.
	* 
	* @param effect The effect for the fireball animation.
	**/
	void StartFireballAnimation(Effect* effect);
	
	/**
	* Starts a burn animation.
	* 
	* @param effect The effect for the burn animation.
	**/
	void StartBurnAnimation(Effect* effect);
	
private:
	/// The object for the player
	PlayerObject*				playerObject;
	/// The object for the enemy
	PlayerObject*				enemyObject;
	/// Queue of effects to be casted by the player
	vector<Effect*>				playerToCast;
	/// List of animating effects
	vector<Effect*>				animatingEffects;
	/// List of free animations
	vector<AnimationObject*>	animations;
	
	/// The object for the player's health
	Object*						playerHealthBar;
	/// The player's total health
	int							totalPlayerHealth;
	/// The player's health
	int							playerHealth;
	/// The player's health (as a percentage)
	double						playerHealthPercent;
	
	/// The object for the enemy's health
	Object*						enemyHealthBar;
	/// The enemy's total health
	int							totalEnemyHealth;
	/// The enemy's health
	int							enemyHealth;
	/// The enemy's health (as a percentage)
	double						enemyHealthPercent;
};

#endif /*BATTLE_REGION_H_*/
